{% extends "base.html" %}

{% block title %}项目详情{% endblock %}

{% block content %}
<div class="container">
    <div class="row mb-4">
        <div class="col">
            <nav aria-label="breadcrumb">
                <ol class="breadcrumb">
                    <li class="breadcrumb-item"><a href="{{ url_for('main.projects') }}">项目管理</a></li>
                    <li class="breadcrumb-item active">项目详情</li>
                </ol>
            </nav>
        </div>
    </div>

    <div class="row">
        <div class="col-md-8">
            <div class="card mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h4 class="mb-0">{{ project.name }}</h4>
                    <span class="badge {% if project.status == 'draft' %}bg-secondary
                                      {% elif project.status == 'pending' %}bg-warning
                                      {% elif project.status == 'approved' %}bg-success
                                      {% elif project.status == 'rejected' %}bg-danger
                                      {% else %}bg-secondary{% endif %}">
                        {% if project.status == 'draft' %}草稿
                        {% elif project.status == 'pending' %}待审核
                        {% elif project.status == 'approved' %}已批准
                        {% elif project.status == 'rejected' %}已拒绝
                        {% else %}未知状态{% endif %}
                    </span>
                </div>
                <div class="card-body">
                    <div class="row mb-3">
                        <div class="col-md-4">
                            <strong>项目编号：</strong>
                        </div>
                        <div class="col-md-8">
                            {{ project.project_code }}
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-4">
                            <strong>项目类型：</strong>
                        </div>
                        <div class="col-md-8">
                            {% if project.project_type == 'industrial' %}
                                工业测控
                            {% elif project.project_type == 'environmental' %}
                                环境监测
                            {% else %}
                                未知类型
                            {% endif %}
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-4">
                            <strong>监测点数量：</strong>
                        </div>
                        <div class="col-md-8">
                            {{ project.scale.monitoring_points }}
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-4">
                            <strong>控制回路数量：</strong>
                        </div>
                        <div class="col-md-8">
                            {{ project.scale.control_loops }}
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-4">
                            <strong>创建时间：</strong>
                        </div>
                        <div class="col-md-8">
                            {{ project.created_at.strftime('%Y-%m-%d %H:%M') }}
                        </div>
                    </div>
                    <div class="row mb-3">
                        <div class="col-md-4">
                            <strong>最后更新：</strong>
                        </div>
                        <div class="col-md-8">
                            {{ project.updated_at.strftime('%Y-%m-%d %H:%M') }}
                        </div>
                    </div>
                </div>
                <div class="card-footer">
                    <div class="btn-group">
                        <a href="{{ url_for('main.projects') }}" class="btn btn-secondary">
                            <i class="fas fa-arrow-left me-1"></i>返回
                        </a>
                        {% if current_user.role == 'manager' or 
                              (current_user.role == 'engineer' and project.creator_id == current_user.id) %}
                        <a href="{{ url_for('main.edit_project', project_id=project.id) }}" 
                           class="btn btn-primary">
                            <i class="fas fa-edit me-1"></i>编辑
                        </a>
                        <button type="button" class="btn btn-danger" data-bs-toggle="modal" 
                                data-bs-target="#deleteProjectModal">
                            <i class="fas fa-trash-alt me-1"></i>删除
                        </button>
                        {% endif %}
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-md-4">
            <!-- 项目状态卡片 -->
            <div class="card mb-4">
                <div class="card-header">
                    <h5 class="mb-0">项目进度</h5>
                </div>
                <div class="card-body">
                    <div class="d-flex justify-content-between mb-2">
                        <span>需求分析</span>
                        <span class="badge bg-success">完成</span>
                    </div>
                    <div class="d-flex justify-content-between mb-2">
                        <span>方案设计</span>
                        <span class="badge bg-warning">进行中</span>
                    </div>
                    <div class="d-flex justify-content-between mb-2">
                        <span>实施部署</span>
                        <span class="badge bg-secondary">未开始</span>
                    </div>
                    <div class="d-flex justify-content-between">
                        <span>验收测试</span>
                        <span class="badge bg-secondary">未开始</span>
                    </div>
                </div>
            </div>

            <!-- 在项目状态卡片后添加环境信息卡片 -->
            <div class="card mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0">环境信息</h5>
                    {% if current_user.role == 'manager' or 
                          (current_user.role == 'engineer' and project.creator_id == current_user.id) %}
                    <a href="{{ url_for('main.edit_environment', project_id=project.id) }}" 
                       class="btn btn-sm btn-outline-primary">
                        <i class="fas fa-edit me-1"></i>编辑
                    </a>
                    {% endif %}
                </div>
                <div class="card-body">
                    {% if project.environment %}
                    <div class="row mb-2">
                        <div class="col-md-4"><strong>温度范围：</strong></div>
                        <div class="col-md-8">{{ project.environment.temperature_range or '未设置' }}</div>
                    </div>
                    <div class="row mb-2">
                        <div class="col-md-4"><strong>湿度范围：</strong></div>
                        <div class="col-md-8">{{ project.environment.humidity_range or '未设置' }}</div>
                    </div>
                    <div class="row mb-2">
                        <div class="col-md-4"><strong>电磁干扰：</strong></div>
                        <div class="col-md-8">{{ project.environment.electromagnetic or '未设置' }}</div>
                    </div>
                    <div class="row">
                        <div class="col-md-4"><strong>空间布局：</strong></div>
                        <div class="col-md-8">{{ project.environment.layout or '未设置' }}</div>
                    </div>
                    {% else %}
                    <p class="text-muted">暂无环境信息</p>
                    {% endif %}
                </div>
            </div>

            <!-- 添加资源信息卡片 -->
            <div class="card mb-4">
                <div class="card-header d-flex justify-content-between align-items-center">
                    <h5 class="mb-0">资源信息</h5>
                    {% if current_user.role == 'manager' or 
                          (current_user.role == 'engineer' and project.creator_id == current_user.id) %}
                    <a href="{{ url_for('main.edit_resource', project_id=project.id) }}" 
                       class="btn btn-sm btn-outline-primary">
                        <i class="fas fa-edit me-1"></i>编辑
                    </a>
                    {% endif %}
                </div>
                <div class="card-body">
                    {% if project.resources %}
                    <div class="row mb-2">
                        <div class="col-md-4"><strong>预算：</strong></div>
                        <div class="col-md-8">{{ "%.2f"|format(project.resources.budget or 0) }} 万元</div>
                    </div>
                    <div class="row mb-2">
                        <div class="col-md-4"><strong>人力资源：</strong></div>
                        <div class="col-md-8">
                            {% if project.resources.human_resources %}
                            <ul class="list-unstyled mb-0">
                                {% for role, count in project.resources.human_resources.items() %}
                                <li>{{ role }}: {{ count }}人</li>
                                {% endfor %}
                            </ul>
                            {% else %}
                            未设置
                            {% endif %}
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-4"><strong>设备资源：</strong></div>
                        <div class="col-md-8">
                            {% if project.resources.equipment %}
                            <ul class="list-unstyled mb-0">
                                {% for item, details in project.resources.equipment.items() %}
                                <li>{{ item }}: {{ details.count }}{{ details.unit }}</li>
                                {% endfor %}
                            </ul>
                            {% else %}
                            未设置
                            {% endif %}
                        </div>
                    </div>
                    {% else %}
                    <p class="text-muted">暂无资源信息</p>
                    {% endif %}
                </div>
            </div>
        </div>
    </div>
</div>

<!-- 添加删除确认对话框 -->
<div class="modal fade" id="deleteProjectModal" tabindex="-1">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title">确认删除</h5>
                <button type="button" class="btn-close" data-bs-dismiss="modal"></button>
            </div>
            <div class="modal-body">
                <p>确定要删除项目 "{{ project.name }}" 吗？此操作不可恢复。</p>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">取消</button>
                <form action="{{ url_for('main.delete_project', project_id=project.id) }}" 
                      method="post" style="display: inline;">
                    <button type="submit" class="btn btn-danger">确认删除</button>
                </form>
            </div>
        </div>
    </div>
</div>
{% endblock %} 